How to Write Seemingly Unhygienic and Referentially Opaque Macros with Syntax-rules
نویسنده
چکیده
This paper details how folklore notions of hygiene and referential transparency of R5RS macros are defeated by a systematic attack. We demonstrate syntax-rules that seem to capture user identi ers and allow their own identi ers to be captured by the closest lexical bindings. In other words, we have written R5RS macros that accomplish what commonly believed to be impossible. We build on the the fundamental technique by Petrofsky of extracting variables from arguments of a macro. The present paper generalizes Petrofsky's idea to attack referential transparency. This paper also shows how to overload the lambda form. The overloaded lambda acts as if it was infected by a virus, which propagates through the lambda's body infecting other lambdas in turn. The virus re-de nes the macro being camou aged after each binding. This rede nition is the key insight in achieving the overall referential opaqueness. Although we eventually subvert all binding forms, we preserve the semantics of Scheme as given in R5RS. The novel result of this paper is a demonstration that although R5RS macros are deliberately restricted in expressiveness, they still wield surprising power. We have exposed faults and the lack of precision in commonly held informal assertions about syntax-rule macros, and pointed out the need for proper formalization. For a practical programmer this paper o ers an encouragement: more and more powerful R5RS macros turn out to be possible.
منابع مشابه
How to Write Seemingly Unhygieni and Referentially Opaque Ma ros with Syntax - rules
This paper details how folklore notions of hygiene and referential transparen y of R5RS ma ros are defeated by a systemati atta k. We demonstrate syntax-rules that seem to apture user identi ers and allow their own identi ers to be aptured by the losest lexi al bindings. In other words, we have written R5RS ma ros that a omplish what ommonly believed to be impossible. We build on the the fundam...
متن کاملA pattern matcher for miniKanren or How to get into trouble with CPS macros
CPS macros written using Scheme’s syntax-rules macro system allow for guaranteed composition of macros and control over the order of macro expansion. We identify a limitation of CPS macros when used to generate bindings from a non-unique list of user-specified identifiers. Implementing a pattern matcher for the miniKanren relational programming language revealed this limitation. Identifiers com...
متن کاملA Stepper for Scheme Macros
Even in the days of Lisp’s simple defmacro systems, macro developers did not have adequate debugging support from their programming environment. Modern Scheme macro expanders are more complex than Lisp’s, implementing lexical hygiene, referential transparency for macro definitions, and frequently source properties. Scheme implementations, however, have only adopted Lisp’s inadequate macro inspe...
متن کاملTwo Approaches to Portable Macros
For any programming language that supports macros and has multiple implementations (each with dierent AST definitions), there is a common problem: how to make macros that operate on ASTs portable among dierent compiler implementations? Implementing portable macros is especially important for statically typed languages like Scala, as IDE vendors usually have dierent implementations of the lan...
متن کاملReading Between the Lines: Distinguishing Macro Code from Open Code in Macros
Have you ever been confused by the sight of bad “SAS® grammar” such as statements that read %IF &X=A %THEN IF X=A...? Have you ever puzzled over how to iteratively generate DATA step DO loops or parts of them? Ever wonder why macros sometimes contain consecutive semicolons? If so, you are not alone. The macro facility enables us to generate open code that varies with circumstances, but of cours...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2002